package com.freewater.springboot.demo.aop.api.advices.afterthrow;

import org.springframework.aop.ThrowsAdvice;

import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.util.Arrays;

public class SimpleThrowing implements ThrowsAdvice {

    public void afterThrowing(ArithmeticException e) {
        System.out.println("\n" + "抛出的异常是：" + e.getClass().getName());
        System.out.println("错误消息：" + e.getMessage());
        System.out.println("导致的原因是：" + e.getCause());
    }

    // 需要注意此方法的参数顺序必须是如下顺序，否则会报java.lang.IllegalArgumentException: argument type mismatch
    public void afterThrowing(Method method, Object[] args, Object target, RemoteException e) {
        System.out.println("\n" + "执行的方法为：" + method.getName());
        System.out.println("方法参数为：" + Arrays.asList(args));
        System.out.println("抛出的异常是：" + e.getClass().getName());
        System.out.println("错误消息：" + e.getMessage());
        System.out.println("导致的原因是：" + e.getCause());
    }
}
